package com.manage.api.controller;

import com.manage.common.result.Result;
import com.manage.pojo.entity.CmSysUser;
import com.manage.service.LawyerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/lawyer")
@Tag(name = "律师管理", description = "律师管理相关接口")
public class LawyerController {

    @Autowired
    private LawyerService lawyerService;

    @Operation(summary = "获取律师列表")
    @GetMapping("/list")
    public Result<List<CmSysUser>> getLawyerList(
            @RequestParam int pageNum,
            @RequestParam int pageSize) {
        return lawyerService.getLawyerList(pageNum, pageSize);
    }

    @Operation(summary = "获取律师详情")
    @GetMapping("/detail/{id}")
    public Result<CmSysUser> getLawyerDetail(@PathVariable Long id) {
        return lawyerService.getLawyerDetail(id);
    }

    @Operation(summary = "添加律师")
    @PostMapping("/add")
    public Result<String> addLawyer(@RequestBody CmSysUser lawyer) {
        return lawyerService.addLawyer(lawyer);
    }

    @Operation(summary = "更新律师信息")
    @PutMapping("/update")
    public Result<String> updateLawyer(@RequestBody CmSysUser lawyer) {
        return lawyerService.updateLawyer(lawyer);
    }
//
//    @Operation(summary = "修改律师状态")
//    @PutMapping("/status/{id}/{status}")
//    public Result<String> changeLawyerStatus(@PathVariable Long id, @PathVariable Integer status) {
//        return lawyerService.changeLawyerStatus(id, status);
//    }

    @Operation(summary = "重置律师密码")
    @PutMapping("/resetPassword/{id}")
    public Result<String> resetLawyerPassword(
            @PathVariable Long id,
            @RequestParam(required = false) String newPassword) {
        String passwordToUse = (newPassword != null && !newPassword.trim().isEmpty()) 
            ? newPassword : "123456";
        return lawyerService.resetLawyerPassword(id, passwordToUse);
    }

    @Operation(summary = "删除律师")
    @DeleteMapping("/delete/{id}")
    public Result<String> deleteLawyer(@PathVariable Long id) {
        return lawyerService.deleteLawyer(id);
    }
}